package com.guigu.servicesms.handler;


import com.guigu.servicesms.utils.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

@Component
public class SmsQuoueHandler {

    @Autowired
    private SmsUtil smsUtil;

    @RabbitListener(queues ="sms_queue")
    public  void listensmsquoue(Message message){

        //拿到保存的手机号和验证码
        Map<String, String> map = (HashMap) message.getPayload();

        //拿到map里面的手机号和验证码
        String phone = map.get("phone");
        String code= map.get("code");

        // 发送短信（第三方服务：阿里云， 腾讯云）
        // 设置短信参数
        String params = "{\"code\":\"[value]\"}";
        params = params.replace("[value]", code);
        smsUtil.sendSms(phone, "SMS_227734165", params);
    }
}
